<!DOCTYPE HTML>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<meta name="description" content="">
<title>微商城-购物车</title>
<link href="{:ADDON_PUBLIC_PATH}/../Template/default/style/myorder.css?v={:SITE_VERSION}" rel="stylesheet" type="text/css">
<link type="text/css" rel="stylesheet" href="__PUBLIC__/Core/js/ext/toastr/toastr.min.css"/>
<script type="text/javascript" src="__STATIC__/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="{:ADDON_PUBLIC_PATH}/../Template/default/js/myorder.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Core/js/ext/toastr/toastr.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Core/js/core.js"></script>
</head>

<body>
<php>

    //验证登录
    if(!is_login()){
    Cookie ( '__forward__', $_SERVER ['REQUEST_URI'] );
    }
</php>
 <BODY>
        <!--头部-->
        <HEADER class="ts1">
            <A class="u_back fl" href="javascript:history.go(-1)">
            </A>
            <UL class="topbar fr">
                <LI>
                    <A class="icon_user" href="{:U('myorder?ctid='.$ctid)}">
                        <I>
                        </I>
                        我的
                    </A>
                </LI>
                <LI>
                    <A class="icon_shopping" href="{:U('myshop?ctid='.$ctid)}">
                        <I>
                        </I>
                        购物车
                    </A>
                </LI>
                <LI>
                    <A class="icon_class" href="{:U('show?id='.$ctid)}">
                        <I>
                        </I>
                        菜单
                    </A>
                </LI>
                <LI>
                    <A class="icon_index" href="{:U('show?id='.$ctid)}">
                        <I>
                        </I>
                        主页
                    </A>
                </LI>
            </UL>
        </HEADER>
        <!--主体-->
        <DIV class="p_floatbox">
            <DIV class="f_list_car p_buy clearfix" id="p_buy">
                <SPAN class="all_price">
                    总价格：
                    <FONT id="all_price" price="{$sumprice}">
                        ￥{$sumprice}
                    </FONT>
                </SPAN>
                <SPAN>
                    总共
                    <FONT id="all_numb" count="{$sumcount}">
                        {$sumcount}
                    </FONT>
                    件商品
                </SPAN>
                <A class="p_btn_buy" href="{:U('myshop?ctid='.$ctid)}">
                    <SPAN class="ts1">
                        进入购物车
                    </SPAN>
                </A>
            </DIV>
        </DIV>
        <div class="main">
			<div class="p_mod">
				<h2 class="p_mod_title">购物车</h2>
				<div class="car">
				<volist name="myshopdatas" id="shop">
					<div class="car_list clearfix">
						<div class="car_content clearfix">
						  <h3><a href="/index.php/addon/Mall/Mall/cpinfo/ctid/{$ctid}/cpid/{$shop.id}.html">{$shop.name}</a></h3>
							 <a href="/index.php/addon/Mall/Mall/cpinfo/ctid/{$ctid}/cpid/{$shop.id}.html">
							  <img src="__ROOT__{$shop.icon|get_cover='path'}" />
							 </a>
							 <div class="car_property">
								<span class="price_now">单价：<font>￥{$shop.price}</font></span>
								<div class="o_num_input clearfix" id="{$shop.id}">
									<a class="minus ts2" href="javascript:;" onclick="plus_minus({$shop.id}, -1,'-{$shop.price}')">-</a>
									<input type="number" min="1" lastnum="1" disabled="disabled" value="{$shop.num}" id="qty{$shop.id}" class="qty" />
									<a class="plus ts2 on" href="javascript:;" onclick="plus_minus({$shop.id},1,'{$shop.price}')">+</a>
								</div>
								<a class="u_order_return delete" href="javascript:;" onclick="delshop('{$shop.id}');">删除商品</a>                     
							 </div>
						</div>
					</div>
				  </volist>
				  <p><span class="price_now" id="total_fee">总价格：<font>{$sumprice}</font></span></p>
				</div>            
			</div>
			<div class="o_btn clearfix">
				<input type="button" class="o_btn_back ts1" onclick="gotoshow()" value="继续购物"/>
				
				<input type="button" class="o_btn_submit ts1" onclick="gotojiesuan()" value="提交订单" />
				
			</div>
		</div>
<style type="text/css">
.desks{ display: none;}
</style>
<script type="text/javascript">
    function showTip(tipTxt) {
        var div = document.createElement('div');
        div.innerHTML = '<div class="deploy_ctype_tip"><p>' + tipTxt + '</p></div>';
        var tipNode = div.firstChild;
        $("#wrap").after(tipNode);
        setTimeout(function() {
            $(tipNode).remove();
        },1500);
    }


function gotoshow(){
	window.location.href='{:U("show?id=".$ctid)}';
}
function gotojiesuan(){

//    var is_follow_login = {$is_follow_login};
//    if (is_follow_login != 2) {
//        showTip('请先登录再提交订单');

//    }
	window.location.href='{:U("jiesuan?ctid=".$ctid)}';
}

function full_update(rowid,price) {
    var _this = $('#qty'+rowid);
    var this_val = parseInt($(_this).val());
    if (this_val < 1 || isNaN(this_val)) {
        alert('购买数量不能小于0！');
        $(_this).focus();
        return false;
    }
    update_cart(rowid, this_val,parseFloat(price));
}
//加减
function plus_minus(rowid, number,price) {
    var num = parseInt($('#qty'+rowid).val());
    num = num + parseInt(number);
    if (num < 1) {
        return false;
    }
     $('#qty'+rowid).attr('value',num);
    update_cart(rowid, parseInt(number),parseFloat(price));     
}

//更新购物车
function update_cart(rowid, num,price) {
	$.ajax({
		url: '/index.php/addon/Mall/Mall/add_cart/ctid/{$ctid}/cpid/'+rowid+'.html',
		data:{num:num},
		type:"POST",
		success: function( data ) {
			if(data == "ok"){
				var oldprice = parseFloat($('#p_buy #all_price').attr("price"));
				oldprice=oldprice+price;
                if (!oldprice)
                {
                    oldprice = 0;
                }
				$('#p_buy #all_price').attr("price",oldprice)
				$('#p_buy #all_price').html('￥'+oldprice);
				var oldcount = parseInt($('#p_buy #all_numb').attr("count"));
				oldcount = oldcount+num;
				$('#p_buy #all_numb').attr("count",oldcount);
				$('#p_buy #all_numb').html(oldcount);
				$('#total_fee font').html('￥'+oldprice);
			}
		}
	});
}

function delshop(shopid){
	$.ajax({
		url: '/index.php/addon/Mall/Mall/delshop/ctid/{$ctid}/cpid/'+shopid+'.html',
		success: function( data ) {
			if(data == "ok"){
				window.location.reload();
			}
		}
	});
}  
</script>
</body>

</html>